package main

import (
	"fmt"
	"log"

	"gitee.com/korbenzhang/gox/xcache"
	"gitee.com/korbenzhang/gox/xcache/rediscache"
	"gitee.com/korbenzhang/gox/xconfig"
	"gitee.com/korbenzhang/gox/xconfig/viperconf"
)

var cache xcache.Cache
var cFile = "/opt/etc/redis.yaml"
var config = viperconf.New()

func main() {
  xconfig.MergeFile(config, cFile)

  // create cache
  cache = rediscache.NewConfigCache(config)

  demoCache(cache)
}

func demoCache(c xcache.Cache){

  // put
  if err:=c.Put("Demo", "Demo Cache");err!=nil{
    log.Println(err)
  }

  // get
  v,err:=c.GetString("Demo")
  if err!=nil{
    log.Print("get Demo err:",err)
  }
  fmt.Println("cache Demo: ", v)

  // check value
  // if v!="Demo Cache"{
  //   log.Print("not got expect: Demo Cache")
  // }
}
